package com.xuecheng.comment.controller;


import com.xuecheng.api.comment.CommentApi;
import com.xuecheng.api.comment.model.dto.CommentDTO;
import com.xuecheng.api.comment.model.qo.CommentModel;
import com.xuecheng.api.comment.model.vo.CommentVO;
import com.xuecheng.comment.convert.CommentConvert;
import com.xuecheng.comment.service.CommentService;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 课程评论功能
 */
@Slf4j
@RestController
public class CommentController implements CommentApi {

    @Autowired
    private CommentService commentService;
    /*
    新增评论
     */
    @PostMapping("/comment/create")
    public CommentDTO createComment(@RequestBody CommentVO vo,String username) {
        CommentDTO commentDTO = CommentConvert.INSTANCE.vo2dto(vo);
        CommentDTO dto = commentService.createComment(commentDTO,username);
        return dto;
    }


//
//    @PostMapping("list")
//    public PageVO<CommentDTO> list(PageRequestParams params, @Valid @RequestBody CommentConditionModel commentModel) {
//        return commentService.list(params, commentModel);
//    }


    @PostMapping("course-comment/for-course")
    public PageVO<CommentDTO> queryCommentList(PageRequestParams params,  @RequestBody CommentModel commentModel) {
        PageVO<CommentDTO> commentDTOS = commentService.queryCommentList(params, commentModel);
//        PageVO<CommentDTO> commentDTOS = teachingApiAgent.queryCommentList(params, commentModel);
        return commentDTOS;
    }


    @PostMapping ( "course-comment/list" )
    public PageVO<CommentDTO> queryCourseCommentList(PageRequestParams params, @RequestBody CommentModel commentModel) {
        PageVO<CommentDTO> commentDTOS = commentService.queryCourseCommentList(params, commentModel);
        return commentDTOS;
    }


    @GetMapping("m/course-comment/list-all")
    public PageVO<CommentDTO> queryMCourseCommentList(PageRequestParams params) {
        PageVO<CommentDTO> commentDTOS = commentService.queryMCourseCommentList(params);
        return commentDTOS;
    }

//    @PostMapping
//    public CommentDTO comment(@Valid @RequestBody CommentDTO commentDTO) {
//        return commentService.addComment(commentDTO);
//    }


    @GetMapping("l/course-statistics/{targetId}")
    public CommentVO statisticsComment(@PathVariable Long targetId) {
        CommentVO commentVO = commentService.queryNums(targetId);
        return commentVO;
    }

    @DeleteMapping("m/delete-comment/{commentId}")
    public void deleteComment(@PathVariable Long commentId) {
        commentService.deleteComment(commentId);
    }


    @DeleteMapping("m/delete-comment/batch-del/{request}")
    public void deleteComments(@PathVariable String request) {
        commentService.deleteComments(request);
    }
}



